import React from 'react'
import { NavBar, Icon } from 'antd-mobile'
// 导入witRouter高阶组件
import {withRouter} from 'react-router-dom'
// 导入props校验包
import PropTypes from 'prop-types'

// import "./index.scss"

// 导入CSSModules 的样式文件
import styles from './index.module.css'

//  顶部导航栏
 function NavHeader({children,history,onLeftClick}) {
  // 默认点击行为   如果用户有传事件进来就用传进来的onLeftClick，否则用defaultHandler
  const defaultHandler = ()=> history.go(-1)

  return <NavBar
    className={styles.navber}
    mode="light"
    icon={<Icon type="left" color="#7c7c7c" size="lg" />}
    onLeftClick={onLeftClick || defaultHandler}
  >{children}</NavBar>

}
NavHeader.propTypes ={
  children:PropTypes.string.isRequired,
  onLeftClick:PropTypes.func
}
export default withRouter(NavHeader)
